import Vue from "vue";
import Router from "vue-router";
import layout from "@/layout/index.vue";

Vue.use(Router);

const routes = [
  {
    path: "/",
    redirect: "/login",
  },

  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/layout",
    component: layout,
    children: [
      {
        path: "/",
        component: () => import("@/layout/Welcome"),
      },
      {
        path: "/users",
        component: () => import("@/views/users/Users"),
      },
      {
        path: "/orders",
        component: () => import("@/views/order/Order.vue"),
      },
      {
        path: "/roles",
        component: () => import("@/views/power/Roles.vue"),
      },
      {
        path: "/rights",
        component: () => import("@/views/power/Rights.vue"),
      },
      {
        path: "/categories",
        component: () => import("@/views/goods/Cate"),
      },
      {
        path: "/params",
        component: () => import("@/views/goods/Params"),
      },
      {
        path: "/goods",
        component: () => import("@/views/goods/List"),
      },
      {
        path: "/goods/add",
        component: () => import("@/views/goods/Add"),
      },
      {
        path: "/reports",
        component: () => import("@/views/report/Report"),
      },
    ],
  },
];

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

// 5. 生成路由对象
const router = new Router({
  // routes: routes, // 固定项 key  : 传入的是规则数组
  routes,
});

export default router;
